/*
 * Copyright (c) 2010 Philip Foulkes <philip.foulkes@gmail.com>
 *
 * This file is free software and is made available under the 
 * terms of the GNU General Public License, version 2, or at your
 * option, any later version
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef _MRP_REGISTRAR_H_
#define _MRP_REGISTRAR_H_

/**
*   Registrar states
*/
#define MRP_REGISTRAR_STATE_MIN 		60 // This needs to be set to the value of the first item in this list 
#define MRP_REGISTRAR_STATE_IN			60 /* Registered */
#define MRP_REGISTRAR_STATE_LV			61 /* Previously registered, but now being timed out */
#define MRP_REGISTRAR_STATE_MT			62 /* Not registered */
#define MRP_REGISTRAR_STATE_MAX			62 // This needs to be set to the value of the last item in this list 
#define MRP_REGISTRAR_STATE_NO_CHANGE 	63 // This needs to be one more than the last itme in the list
#define MRP_REGISTRAR_STATE_NUM			(MRP_REGISTRAR_STATE_MAX - MRP_REGISTRAR_STATE_MIN + 1)

/**
*   Registrar Administrative Controls 
*/
#define MRP_REGISTRAR_ADMINISTRATIVE_CONTROL_MIN					0
#define MRP_REGISTRAR_ADMINISTRATIVE_CONTROL_NORMAL_REGISTRATION	0
#define MRP_REGISTRAR_ADMINISTRATIVE_CONTROL_REGISTRATION_FIXED		1
#define MRP_REGISTRAR_ADMINISTRATIVE_CONTROL_REGISTRATION_FORBIDDEN	2
#define MRP_REGISTRAR_ADMINISTRATIVE_CONTROL_MAX					2

/**
*   The job of the Registrar is to record declarations of the attribute made by other Participants on the LAN. It
*   does not send any protocol messages, as the Applicant looks after the interests of all would-be Participants.
*/
struct mrp_registrar
{
	struct mrp_state_machine mrp_state_machine; /* this has to be the first member */
	
	int registrar_administrative_control; /* These parameters allow administrative control to be exercised over the registration state of each Attribute value, and hence, via the propagation mechanism provided by MAP allow control to be exercised over the propagation of declarations. */
	struct timer_list leavetimer;
	
	struct mrp_attribute * mrp_attribute;
};

struct mrp_registrar * mrp_registrar_create_and_init (struct mrp_attribute * mrp_attribute);
void mrp_registrar_destroy (struct mrp_registrar ** mrp_registrar);

int mrp_registrar_is_registered (struct mrp_registrar * mrp_registrar);
int mrp_registrar_is_leaving (struct mrp_registrar * mrp_registrar);
int mrp_registrar_is_empty (struct mrp_registrar * mrp_registrar);

int mrp_registrar_set_registrar_administrative_control (struct mrp_registrar * mrp_registrar, int registrar_administrative_control);

#endif
